package com.example.webtest.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@Slf4j
public class test {
	private static String a="4444";
	private static ThreadLocal<String> threadLocal=new ThreadLocal<>();


	@ResponseBody
	@RequestMapping("/test")
	public String test(HttpSession httpSession) throws InterruptedException {


		log.info("{}进入了",Thread.currentThread().getName());

		for (int i = 0; i < 1000000; i++) {
			System.out.print(".");
		}
		log.info("{}处理完成",Thread.currentThread().getName());
		httpSession.removeAttribute("pp");
		return Thread.currentThread().getName();
	}
	@ResponseBody
    @RequestMapping("/set")
	public String set(HttpSession httpSession){
		httpSession.setAttribute("pp","zjh");
		return "成功";
	}





	@RequestMapping("/view")
	public String view(){
		return "test";
	}

    @ResponseBody
	@RequestMapping("/setThread")
	public String setT(){
		threadLocal.set(Thread.currentThread().getName());
		System.out.println(Thread.currentThread().getName());
		return Thread.currentThread().getName()+"设置完成";
	}


	@ResponseBody
	@RequestMapping("/getThread")
	public String getT(){
		System.out.println(Thread.currentThread().getName()+":"+threadLocal.get());
		return Thread.currentThread().getName()+"::"+threadLocal.get();
	}












}
